package com.asset.salesforce.activities;

import java.util.ArrayList;

import com.asset.salesforce.R;
import com.asset.salesforce.adapters.NewAdapter;
import com.asset.salesforce.handlers.DialogHandler;

import android.os.Bundle;
import android.app.ExpandableListActivity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ExpandableListView;
import android.widget.Toast;
import android.widget.ExpandableListView.OnChildClickListener;

public class AccountActivity  extends ExpandableListActivity implements
OnChildClickListener {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ExpandableListView expandbleLis = getExpandableListView();
expandbleLis.setDividerHeight(2);
expandbleLis.setGroupIndicator(null);
expandbleLis.setClickable(true);
expandbleLis.setOnItemLongClickListener(new OnItemLongClickListener() {
	@Override
	public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		DialogHandler.listDialogHandler(AccountActivity.this);
		return true;
	}
});
setGroupData();
setChildGroupData();

NewAdapter mNewAdapter = new NewAdapter(groupItem, childItem);
mNewAdapter
		.setInflater(
				(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE),
				this);
getExpandableListView().setAdapter(mNewAdapter);
expandbleLis.setOnChildClickListener(this);
}

public void setGroupData() {
groupItem.add("Account1");
groupItem.add("Account2");
groupItem.add("Account3");
groupItem.add("Account4");
}

ArrayList<String> groupItem = new ArrayList<String>();
ArrayList<Object> childItem = new ArrayList<Object>();

public void setChildGroupData() {

ArrayList<String> child = new ArrayList<String>();
child.add("Name:Hisham Mounir");
child.add("Phone:01208605874");
child.add("Email:hisham.wasp@gmail.com");
child.add("Address:Abasyia");
childItem.add(child);

child = new ArrayList<String>();
child.add("Name:Hisham Ahmed");
child.add("Phone:01208605874");
child.add("Email:hisham.wasp@gmail.com");
child.add("Address:Abasyia");
childItem.add(child);

child = new ArrayList<String>();
child.add("Name:Hisham Mohammed");
child.add("Phone:01208605874");
child.add("Email:hisham.wasp@gmail.com");
child.add("Address:Abasyia");
childItem.add(child);

child = new ArrayList<String>();
child.add("Name:Hisham Elkadraway");
child.add("Phone:01208605874");
child.add("Email:hisham.wasp@gmail.com");
child.add("Address:Abasyia");
childItem.add(child);
}

@Override
public boolean onChildClick(ExpandableListView parent, View v,
	int groupPosition, int childPosition, long id) {
Toast.makeText(AccountActivity.this, "Clicked On Child",
		Toast.LENGTH_SHORT).show();
return true;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
	// Inflate the menu; this adds items to the action bar if it is present.
	getMenuInflater().inflate(R.menu.main, menu);
	return true;
}
}
